<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="/js/jquery.min.js"></script>
    <script src="../layui/layui.all.js" charset="utf-8"></script>
</head>
<body>
<!--

<button type="button" class="layui-btn" id="test1">
    <i class="layui-icon">&#xe67c;</i>点我可以把excel数据上传到数据库中
</button>-->
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">想查谁</label>
        <div class="layui-input-block">
            <textarea id="employeeId" name="employeeId"  placeholder="请输入人名或者组名为空默认全部门"
                      class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">查几月</label>
        <div class="layui-input-block">
            <input type="text" id="month" name="month">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">

        <label class="layui-form-label">机密数据</label>
        <div class="layui-input-block">
            <textarea id="Cookie" name="Cookie" placeholder="泄密就是叛国,机密数据每天只需要输入一次就可以"
                      class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">个人明细</button>
<!--
            <button id="resetreset" type="reset" class="layui-btn layui-btn-primary">重置</button>
-->
            <button class="layui-btn" id="suangua" type="button" class="layui-btn layui-btn-primary">让gpt给我开一卦</button>
            <button class="layui-btn" id="zhuanpan" type="button" class="layui-btn layui-btn-primary">本月幸运小转盘</button>
        </div>
    </div>
</form>
<table id="tableId" lay-filter="test"></table>
<script>

    layui.use('upload', function () {
        var upload = layui.upload;

        //拖拽上传
        upload.render({
            elem: '#kaoqin10'
            , accept: "file"
            , url: '/easyExcel/upload' //改成您自己的上传接口
            , done: function (res) {
                layer.msg('上传成功');
                layui.$('#uploadDemoView').removeClass('layui-hide')
                layui.$('#sql').val(res.data)
                console.log(res)
            }
        });
        /*//执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,accept: "file"
            ,url: '/easyExcel/upload' //上传接口
            ,done: function(res){
                //上传完毕回调
                layer.msg(res.retInfo);
            }
            ,error: function(){
                //请求异常回调
            }
        });*/
    });
</script>

<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            // layer.msg(JSON.stringify(data.field));
          /*  if (data.field["Cookie"] == null || data.field["Cookie"] == "") {
                layer.msg("没有机密数据,你让我查个der", {icon: 5, timeout: 3000});
                $("#sql").focus()
                return false;
            }*/
            $(function () {
                $.ajax({
                    url: "/easyExcel/kaoqin",
                    contentType: "application/json;charset=UTF-8"
                    , type: "POST"
                    , data: JSON.stringify(data.field)
                    , dataType: "JSON",
                    beforeSend: function () {
                        layui.table.render({
                            elem: "#tableId"
                            , limit: 10000
                            , toolbar: true
                            , data: {}
                            , cols: {}
                        });
                        this.layerIndex = layer.load(0, {
                            shade: [0.3, '#393D49']
                            /*,
                            content: '<span class="loadtip">耗时操作处理中,请稍候...</span>',
                            success: function (layer) {
                                layer.find('.layui-layer-content').css({
                                    'padding-top': '30px',
                                    'width': '300px',
                                });
                                layer.find('.loadtip').css({
                                    'font-size':'18px',
                                    'margin-left':'5px',
                                    color:'#0000FF'
                                });
                            }*/
                        });
                        // layer.msg("耗时操作开始请稍后", {
                        //     icon: 6//成功的表情
                        // });
                    },
                    success: function (res) {
                        layer.msg("执行查询成功啦", {
                            icon: 6,//成功的表情
                            timeout: 1000
                        });
                        layui.table.render({
                            elem: "#tableId"
                            , limit: 10000
                            , toolbar: true
                            , data: res.tableData
                            , cols: res.cols
                        });
                    }, error: function (data) {
                        layer.msg(data.responseText, {icon: 5});
                    },
                    complete: function () {
                        layer.close(this.layerIndex);
                        $("#sql").focus();
                    }
                });
            });
            return false;
        });
        $("#resetreset").on("click", function () {
            $("#sql").focus();
            debugger;
            var formatDate = function (date) {
                var y = date.getFullYear();
                var m = date.getMonth() + 1;
                m = m < 10 ? '0' + m : m;
                var d = date.getDate();
                d = d < 10 ? ('0' + d) : d;
                return y + '-' + m;
            };
            $("#month").attr("value", formatDate(new Date()));

        });

    });

    $("#suangua").on("click", function () {
        layer.open({
            type: 1,
            content: '<form class="layui-form" action="">\n' +
                '    <div class="layui-form-item layui-form-text">\n' +
                '        <label class="layui-form-label">GPT400测算结果</label>\n' +
                '        <div class="layui-input-block">\n' +
                '            <textarea id="kaoqindia" name="kaoqin" placeholder="请输入想加班的分钟数.默认值60" class="layui-textarea"></textarea>\n' +
                '        </div>\n' +
                '    </div>\n' +
                '</form>'
            , btn: ['帮我算算吧', '我想当卷王', '我想划划水', '我想和领导谈谈心', '我想当潜水王']
            , area: ['500px', '300px']
            , yes: function (index, layero) {
                // $("#kaoqindia").val($("#kaoqin").val());
                var suanguajson = {
                    "Cookie": '',
                    "jiabanavgmin": '60'
                }
                var aaa = $("#kaoqindia").val();
                let reg = /^(\+|-)?\d+$/;
                if (reg.test(aaa) && aaa > -1) {
                    suanguajson['jiabanavgmin'] = aaa;
                }
                suanguajson.Cookie = $("#Cookie").val();
                suanguajson.employeeId = $("#employeeId").val();
                suanguajson.month = $("#month").val();
                $.ajax({
                    url: "/easyExcel/kaoqin",
                    contentType: "application/json;charset=UTF-8"
                    , type: "POST"
                    , data: JSON.stringify(suanguajson)
                    , dataType: "JSON",
                    beforeSend: function () {
                        layui.table.render({
                            elem: "#tableId"
                            , limit: 10000
                            , toolbar: true
                            , data: {}
                            , cols: {}
                        });
                        this.layerIndex = layer.load(0, {
                            shade: [0.3, '#393D49']
                            /*,
                            content: '<span class="loadtip">耗时操作处理中,请稍候...</span>',
                            success: function (layer) {
                                layer.find('.layui-layer-content').css({
                                    'padding-top': '30px',
                                    'width': '300px',
                                });
                                layer.find('.loadtip').css({
                                    'font-size':'18px',
                                    'margin-left':'5px',
                                    color:'#0000FF'
                                });
                            }*/
                        });
                        // layer.msg("耗时操作开始请稍后", {
                        //     icon: 6//成功的表情
                        // });
                    },
                    success: function (res) {
                        layer.msg("执行查询成功啦", {
                            icon: 6,//成功的表情
                            timeout: 1000
                        });
                        layui.table.render({
                            elem: "#tableId"
                            , limit: 10000
                            , toolbar: true
                            , data: res.tableData
                            , cols: res.cols
                        });
                        $("#kaoqindia").val(res.suanguaresult)
                    }, error: function (data) {
                        layer.msg(data.responseText, {icon: 5});
                    },
                    complete: function () {
                        layer.close(this.layerIndex);
                        $("#sql").focus();
                    }
                });
                console.log(layero);
            }
            , btn2: function (index, layero) {
                $("#kaoqindia").val(120)
                return false;
            }
            , btn3: function (index, layero) {
                $("#kaoqindia").val(45)
                return false;
                //return false 开启该代码可禁止点击该按钮关闭
            }
            , btn4: function (index, layero) {
                $("#kaoqindia").val(30)
                return false;
                //return false 开启该代码可禁止点击该按钮关闭
            }, btn5: function (index, layero) {
                $("#kaoqindia").val(60)
                return false;
                //return false 开启该代码可禁止点击该按钮关闭
            }

            , cancel: function () {
                //右上角关闭回调

                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    });
    $("#zhuanpan").on("click", function () {
        var suanguajson = {
            "month": '',
            "Cookie": '',
            "employeeId": ''
        }
        suanguajson.Cookie = $("#Cookie").val();
        suanguajson.month = $("#month").val();
        suanguajson.employeeId = $("#employeeId").val();
        $.ajax({
            url: "/easyExcel/zfzkaoqin",
            contentType: "application/json;charset=UTF-8"
            , type: "POST"
            , data: JSON.stringify(suanguajson)
            , dataType: "JSON",
            beforeSend: function () {
                layui.table.render({
                    elem: "#tableId"
                    , limit: 10000
                    , toolbar: true
                    , data: {}
                    , cols: {}
                });
                this.layerIndex = layer.load(0, {
                    shade: [0.3, '#393D49']
                    /*,
                    content: '<span class="loadtip">耗时操作处理中,请稍候...</span>',
                    success: function (layer) {
                        layer.find('.layui-layer-content').css({
                            'padding-top': '30px',
                            'width': '300px',
                        });
                        layer.find('.loadtip').css({
                            'font-size':'18px',
                            'margin-left':'5px',
                            color:'#0000FF'
                        });
                    }*/
                });
                // layer.msg("耗时操作开始请稍后", {
                //     icon: 6//成功的表情
                // });
            },
            success: function (res) {
                layer.msg("执行查询成功啦", {
                    icon: 6,//成功的表情
                    timeout: 1000
                });
                layui.table.render({
                    elem: "#tableId"
                    , limit: 10000
                    , toolbar: true
                    , data: res.tableData
                    , cols: res.cols
                });
                $("#kaoqindia").val(res.suanguaresult)
            }, error: function (data) {
                layer.msg(data.responseText, {icon: 5});
            },
            complete: function () {
                layer.close(this.layerIndex);
                $("#sql").focus();
            }
        });

/*
        layer.open({
            type: 1,
            content: '<form class="layui-form" action="">\n' +
                '    <div class="layui-form-item layui-form-text">\n' +
                '        <label class="layui-form-label">GPT500测算结果</label>\n' +
                '        <div class="layui-input-block">\n' +
                '            <textarea id="zhuanpanres" name="zhuanpanres" placeholder="转盘结果将在这里显示" class="layui-textarea"></textarea>\n' +
                '        </div>\n' +
                '    </div>\n' +
                '</form>'
            +'<table id="zhuanpanTableId" lay-filter="test"></table>\n'
            , btn: ['让子弹飞吧', '我想当卷王', '我想划划水', '我想和领导谈谈心', '我想当潜水王']
            , area: ['1500px', '800px']
            , yes: function (index, layero) {
                // $("#kaoqindia").val($("#kaoqin").val());
                var suanguajson = {
                    "month": '',
                    "Cookie": ''
                }
                suanguajson.Cookie = $("#Cookie").val();
                suanguajson.month = $("#month").val();
                $.ajax({
                    url: "/easyExcel/zfzkaoqin",
                    contentType: "application/json;charset=UTF-8"
                    , type: "POST"
                    , data: JSON.stringify(suanguajson)
                    , dataType: "JSON",
                    beforeSend: function () {
                        layui.table.render({
                            elem: "#zhuanpanTableId"
                            , limit: 10000
                            , toolbar: true
                            , data: {}
                            , cols: {}
                        });
                        this.layerIndex = layer.load(0, {
                            shade: [0.3, '#393D49']
                            /!*,
                            content: '<span class="loadtip">耗时操作处理中,请稍候...</span>',
                            success: function (layer) {
                                layer.find('.layui-layer-content').css({
                                    'padding-top': '30px',
                                    'width': '300px',
                                });
                                layer.find('.loadtip').css({
                                    'font-size':'18px',
                                    'margin-left':'5px',
                                    color:'#0000FF'
                                });
                            }*!/
                        });
                        // layer.msg("耗时操作开始请稍后", {
                        //     icon: 6//成功的表情
                        // });
                    },
                    success: function (res) {
                        layer.msg("执行查询成功啦", {
                            icon: 6,//成功的表情
                            timeout: 1000
                        });
                        layui.table.render({
                            elem: "#zhuanpanTableId"
                            , limit: 10000
                            , toolbar: true
                            , data: res.tableData
                            , cols: res.cols
                        });
                        $("#kaoqindia").val(res.suanguaresult)
                    }, error: function (data) {
                        layer.msg(data.responseText, {icon: 5});
                    },
                    complete: function () {
                        layer.close(this.layerIndex);
                        $("#sql").focus();
                    }
                });
                console.log(layero);
            }
            , btn2: function (index, layero) {
                $("#kaoqindia").val(120)
                return false;
            }
            , btn3: function (index, layero) {
                $("#kaoqindia").val(45)
                return false;
                //return false 开启该代码可禁止点击该按钮关闭
            }
            , btn4: function (index, layero) {
                $("#kaoqindia").val(30)
                return false;
                //return false 开启该代码可禁止点击该按钮关闭
            }, btn5: function (index, layero) {
                $("#kaoqindia").val(60)
                return false;
                //return false 开启该代码可禁止点击该按钮关闭
            }

            , cancel: function () {
                //右上角关闭回调

                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
*/
    });
    layui.form.on('select(employeeId)', function (data) {
        wwl();
    });
    layui.form.render();
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#month' //指定元素
            , value: new Date()
            , type: 'month'
            , done: function (value, date, endDate) {
                console.log(value); //得到日期生成的值，如：2017-08-18
                /*console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。*/
                wwl(value)
            }
        });
    });

    function wwl(date) {
        let currentdate = $("#month").val();
        if (!!date) {
            currentdate = date;
        }
        let currentperson = $("#employeeId").val();
        let currentUrl = "http://eip.hengchang6.com/api/portal/compo/attendance/composite_info?month=" + currentdate + "&employeeId=" + currentperson
        $("#huoqushuju").attr("href", currentUrl);
        console.log(currentUrl);
    }

    wwl();


</script>
</body>
</html>